package com.fingard.dsp.bank.directbank.boc01;

import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.bankInterface.IRealTime;
import com.fingard.dsp.bank.reqrespobj.single.ReqQrySingle;
import com.fingard.dsp.bank.reqrespobj.single.ReqSingle;
import com.fingard.dsp.bank.reqrespobj.single.RetAtsSingle;
import com.fingard.dsp.bank.reqrespobj.single.detail.RetAtsSglDetail;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

public class BOC01RealTime extends BOC01Base implements IRealTime {

    @Override
    public RetAtsSingle d_9108_RealTimeRec(ReqSingle p_req9108) throws Exception {
        //返回ATS的对象
        RetAtsSingle retAts = new RetAtsSingle(p_req9108.reqHeader);
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        if ("2".equals(p_req9108.singleDetail.isPrivate)) {//单笔对公实时代扣
            tmpRetDetail = d_9108_pub_b2e0009(p_req9108);
        } else if ("1".equals(p_req9108.singleDetail.isPrivate)) {//单笔对私实时代扣
            tmpRetDetail = d_9108_pri_b2e0191(p_req9108);
        }
        if (tmpRetDetail.respCode.equals("-1") && StringHelper.isNullOrEmpty(tmpRetDetail.reqSeqID)) {
            tmpRetDetail.reqSeqID = p_req9108.singleDetail.askNumber;
        }
        retAts.writeRetDetail(tmpRetDetail);
        return retAts;
    }

    //单笔对公实时代扣
    private RetAtsSglDetail d_9108_pub_b2e0009(ReqSingle p_req9108) throws Exception {
        RetAtsSglDetail retDetail = new RetAtsSglDetail();
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0009";//交易代码
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            //写入通用的头部节点
            //Date tmpDateNow = new Date();
            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            xmlWriter.writeElementClosed("ceitinfo");
            xmlWriter.writeElementString("transtype", getBankConfig().getValueAsString("transtype"));

            XElement tmpXElement = new XElement(bankHeader.trncod + "-rq", "");
            tmpXElement.addChild(new XElement("insid", p_req9108.singleDetail.askNumber));

            XElement fractnXElement = new XElement("fractn", "");

            fractnXElement.addChild(new XElement("fribkn", "1".equals(p_req9108.singleDetail.sameBnk) ? "" : p_req9108.singleDetail.payArea));
            fractnXElement.addChild(new XElement("actacn", p_req9108.singleDetail.payAct));
            fractnXElement.addChild(new XElement("actnam", p_req9108.singleDetail.payName));
            tmpXElement.addChild(fractnXElement);

            XElement toactnXElement = new XElement("toactn", "");
            if (p_req9108.singleDetail.sameBnk.equals("1")) {
                toactnXElement.addChild(new XElement("toibkn", p_req9108.singleDetail.recArea));
            } else {
                toactnXElement.addChild(new XElement("toibkn", p_req9108.singleDetail.cnapsCode));
            }
            toactnXElement.addChild(new XElement("actacn", p_req9108.singleDetail.recAct));
            toactnXElement.addChild(new XElement("toname", p_req9108.singleDetail.recName));
            toactnXElement.addChild(new XElement("toaddr", ""));
            toactnXElement.addChild(new XElement("tobknm", p_req9108.singleDetail.getOppBankLocation()));
            tmpXElement.addChild(toactnXElement);

            tmpXElement.addChild(new XElement("trnamt", p_req9108.singleDetail.payAmount));
            tmpXElement.addChild(new XElement("trncur", this.convertCurToBank(p_req9108.singleDetail.payCur)));
            if (p_req9108.singleDetail.paySpd.equals("1")) {
                tmpXElement.addChild(new XElement("priolv", "1"));
            } else {
                tmpXElement.addChild(new XElement("priolv", "0"));
            }

            tmpXElement.addChild(new XElement("furinfo", p_req9108.singleDetail.purpose));
            tmpXElement.addChild(new XElement("trfdate", Format.Date8Format.format(p_req9108.singleDetail.getPayDateTime())));
            //xmlWriter.writeElementClosed("trftime");
            tmpXElement.addChild(new XElement("comacn", p_req9108.singleDetail.payAct));
            nodeAnalysis(p_req9108.singleDetail.srcXElement, tmpXElement, getCharset());
            xmlWriter.writeXElement(tmpXElement);
            //XElement tmpXElement = new XElement("DCOPDPAYX","");
            //tmpXElement.addChild(new XElement("YURREF",p_req1908.singleDetail.askNumber));
            //xmlWriter.writeXElement(tmpXElement);

            xmlWriter.writeEndDocument();//写入报文完成
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());//发送银行
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                //解析银行返回
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0009-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0009-rs/status/rspmsg");
                    if (isActiveRetCode(tmprspcod)) {
                        //retDetail.respCode = "0";
                        //retDetail.respInfo = tmpRetMsg;
                        //retDetail.reqSeqID = tmpBkReader.getFirstText("/CMS/eb/pub/fSeqno");
                        if (tmpBkReader.read("/bocb2e/trans/trn-b2e0009-rs/b2e0009-rs")) {
                            retDetail.respCode = "0";
                            retDetail.transState = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                            retDetail.payInfoCode = retDetail.transState;
                            retDetail.respInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                            retDetail.reqSeqID = tmpBkReader.readedXElement.getSingleText("insid");
                        } else {
                            retDetail.respCode = "0";
                            retDetail.transState = tmprspcod;
                            retDetail.payInfoCode = tmprspcod;
                            retDetail.respInfo = tmprspmsg;
                            retDetail.reqSeqID = p_req9108.singleDetail.askNumber;
                        }
                    } else {
                        retDetail.respCode = "-1";
                        if (StringHelper.isNullOrEmpty(tmprspmsg)) {
                            tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                        }
                        retDetail.respInfo = tmprspmsg;
                    }
                } else {
                    retDetail.respCode = "-1";
                    retDetail.respInfo = tmpSbMsg.toString();
                }
            } else if (tmpStrRet[0].equals(ConnState.FAIL)) {
                retDetail.respCode = "0";
                retDetail.respInfo = tmpStrRet[1];
                retDetail.reqSeqID = p_req9108.singleDetail.askNumber;
                retDetail.transState = PaymentState.FAIL_Payment;
                retDetail.payInfoCode = tmpStrRet[0];
            } else {
                retDetail.respCode = "-1";
                retDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            retDetail.respCode = "-1";
            retDetail.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        return retDetail;
    }

    //单笔对私实时代扣
    private RetAtsSglDetail d_9108_pri_b2e0191(ReqSingle p_req9108) throws Exception {
        //返回ATS的对象
        RetAtsSglDetail retDetail = new RetAtsSglDetail();
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            bankHeader.trncod = "b2e0191";//交易代码
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
            xmlWriter.writeElementString("insid", p_req9108.singleDetail.askNumber);

            xmlWriter.writeElementString("toibkn", p_req9108.singleDetail.recArea);
            xmlWriter.writeElementString("toactacn", p_req9108.singleDetail.recAct);
            xmlWriter.writeElementString("cdate", Format.Date8Format.format(new Date()));
            if (p_req9108.singleDetail.sameBnk.equals("1")) {//paytyp 1：中行 0：他行
                xmlWriter.writeElementString("paytyp", "1");
            } else {
                xmlWriter.writeElementString("paytyp", "0");
            }
            xmlWriter.writeElementString("txncur", this.convertCurToBank(p_req9108.singleDetail.recCur));
            xmlWriter.writeElementString("pybamt", p_req9108.singleDetail.payAmount);
            xmlWriter.writeElementString("pybnum", "1");


            String furinfo = getBankConfig().getMapValueByKey("furinfo" + bankHeader.trncod, p_req9108.singleDetail.purpose);

            xmlWriter.writeElementString("useinf", furinfo);
            xmlWriter.writeElementString("furinfo", p_req9108.singleDetail.abstractATS);

            //需要进行对账码拼接以及节点解析，采用XElement进行处理

            XElement tmpXElement = new XElement("detail", "");

            String area = "";
            String standardArea = "";

            area = p_req9108.singleDetail.payArea;
            standardArea = p_req9108.singleDetail.payStandardArea;

            String areaMapped = "";
            if (StringHelper.hasAnyChar(standardArea)) {
                areaMapped = getBankConfig().getMapValueByKey("areaMapping", standardArea);
            }
            if (StringHelper.isNullOrEmpty(areaMapped)) {
                areaMapped = getBankConfig().getMapValueByKey("areaMapping", area);
            }


            if (p_req9108.singleDetail.sameBnk.equals("1")) {
                tmpXElement.addChild(new XElement("bcode", areaMapped));
            } else {
                tmpXElement.addChild(new XElement("bcode", p_req9108.singleDetail.cnapsCode));
            }
            tmpXElement.addChild(new XElement("fractacn", p_req9108.singleDetail.payAct));
            tmpXElement.addChild(new XElement("frname", p_req9108.singleDetail.payName));
            String certType = convertCertTypeToBank(p_req9108.singleDetail.certType);
            certType = StringHelper.hasAnyChar(certType) ? certType : "01";
            tmpXElement.addChild(new XElement("fridtp", certType));
            tmpXElement.addChild(new XElement("fridet", p_req9108.singleDetail.certNum));
            tmpXElement.addChild(new XElement("pydamt", p_req9108.singleDetail.payAmount));
            tmpXElement.addChild(new XElement("agrno", ""));
            tmpXElement.addChild(new XElement("furinfo", p_req9108.singleDetail.askNumber));
            tmpXElement.addChild(new XElement("useinf", ""));
            nodeAnalysis(p_req9108.singleDetail.srcXElement, tmpXElement, getCharset());
            xmlWriter.writeXElement(tmpXElement);

            xmlWriter.writeEndDocument();//写入报文完成
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());//发送银行
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                //解析银行返回
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");
                    if (isActiveRetCode(tmprspcod)) {
                        if (tmpBkReader.read("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs")) {
                            retDetail.respCode = "0";
                            retDetail.transState = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                            retDetail.payInfoCode = retDetail.transState;
                            retDetail.respInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                            retDetail.reqSeqID = tmpBkReader.readedXElement.getSingleText("insid");
                        } else {
                            retDetail.respCode = "0";
                            retDetail.transState = tmprspcod;
                            retDetail.payInfoCode = tmprspcod;
                            retDetail.respInfo = tmprspmsg;
                            retDetail.reqSeqID = p_req9108.singleDetail.askNumber;
                        }
                    } else {
                        retDetail.respCode = "-1";
                        retDetail.transState = tmprspcod;
                        retDetail.respInfo = tmprspmsg;
                    }
                } else {
                    retDetail.respCode = "-1";
                    retDetail.respInfo = tmpSbMsg.toString();
                }
            } else if (tmpStrRet[0].equals(ConnState.FAIL)) {
                retDetail.respCode = "0";
                retDetail.respInfo = tmpStrRet[1];
                retDetail.reqSeqID = p_req9108.singleDetail.askNumber;
                retDetail.transState = PaymentState.FAIL_Payment;
                retDetail.payInfoCode = tmpStrRet[0];
            } else {
                retDetail.respCode = "-1";
                retDetail.respInfo = tmpStrRet[1];
            }

        } catch (Exception e) {
            retDetail.respCode = "-1";
            retDetail.respInfo = e.toString();
            e.printStackTrace();
        }
        return retDetail;
    }

    @Override
    public RetAtsSingle d_9144_QryRealTimeRec(ReqQrySingle p_req9144) throws Exception {
        //返回ATS的对象
        RetAtsSingle retAts = new RetAtsSingle(p_req9144.reqHeader);
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        if ("2".equals(p_req9144.isPrivate)) {//单笔对公实时代扣状态查询
            tmpRetDetail = d_9144_b2e0007(p_req9144);
        } else if ("1".equals(p_req9144.isPrivate)) {//单笔对私实时代扣状态查询
            tmpRetDetail = d_9144_b2e0190(p_req9144);
        }
        if (tmpRetDetail.respCode.equals("-1") && StringHelper.isNullOrEmpty(tmpRetDetail.reqSeqID)) {
            tmpRetDetail.reqSeqID = p_req9144.askNumber;
        }
        retAts.writeRetDetail(tmpRetDetail);
        return retAts;
    }

    //单笔对公实时代扣状态查询
    private RetAtsSglDetail d_9144_b2e0007(ReqQrySingle p_req9144) throws Exception {
        RetAtsSglDetail retDetail = new RetAtsSglDetail();
        BOC01Header bankHeader = new BOC01Header();
        bankHeader.trncod = "b2e0007";//交易代码
        bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
        writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
        xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
        xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
        xmlWriter.writeElementString("insid", p_req9144.askNumber);
        xmlWriter.writeElementClosed("obssid");
        xmlWriter.writeEndDocument();
        try {
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");
                    if (isActiveRetCode(tmprspcod)) {
                        //retDetail.respCode = "0";
                        //retDetail.respInfo = tmpRetMsg;
                        //retDetail.reqSeqID = tmpBkReader.getFirstText("/CMS/eb/pub/fSeqno");
                        if (tmpBkReader.read("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs")) {
                            String tmpRetCode = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                            String tmpRetInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                            retDetail.respCode = "0";
                            retDetail.transState = tmpRetCode;
                            retDetail.payInfoCode = retDetail.transState;
                            retDetail.respInfo = tmpRetInfo;
                            retDetail.reqSeqID = tmpBkReader.readedXElement.getSingleText("insid");
                        } else {
                            retDetail.respCode = "-1";
                            retDetail.respInfo = tmprspmsg;
                            retDetail.reqSeqID = p_req9144.askNumber;
                        }
                    } else {
                        retDetail.respCode = "-1";
                        if (StringHelper.isNullOrEmpty(tmprspmsg)) {
                            tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                        }
                        retDetail.respInfo = tmprspmsg;
                    }
                } else {
                    retDetail.respCode = "-1";
                    retDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                retDetail.respCode = "-1";
                retDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception e) {
            retDetail.respCode = "-1";
            retDetail.respInfo = e.getMessage();
            e.printStackTrace();
        }
        return retDetail;
    }

    //单笔对公实时代扣状态查询
    private RetAtsSglDetail d_9144_b2e0022(ReqQrySingle p_req9144) throws Exception {
        //返回ATS的对象
        RetAtsSglDetail retDetail = new RetAtsSglDetail();
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0022";
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
            xmlWriter.writeElementString("ibknum", p_req9144.payArea);
            xmlWriter.writeElementString("actacn", p_req9144.payAct);
            xmlWriter.writeStartElement("datescope");
            String bgnDate = Format.Date8Format.format(p_req9144.getBgnDateTime());
            xmlWriter.writeElementString("from", bgnDate);
            xmlWriter.writeElementString("to", bgnDate);
            xmlWriter.writeEndElement();
            xmlWriter.writeElementString("remtyp", "1");
            xmlWriter.writeElementString("prdtyp", "0");
            xmlWriter.writeElementString("chltyp", "0");
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);

                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");
                    if (isActiveRetCode(tmprspcod)) {
                        boolean isMatch = false;
                        while (tmpBkReader.read("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs")) {
                            String insid = tmpBkReader.readedXElement.getSingleTextNotNull("insid");
                            if (insid.equals(p_req9144.askNumber)) {
                                isMatch = true;
                                String tmpRetCode = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                                String tmpRetInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                                retDetail.respCode = "0";
                                retDetail.transState = tmpRetCode;
                                retDetail.payInfoCode = retDetail.transState;
                                retDetail.respInfo = tmpRetInfo;
                                retDetail.reqSeqID = insid;
                                break;
                            }
                        }

                        if (!isMatch) {
                            if (getBankConfig().getValueAsString("canBeFailed").contains(p_req9144.askNumber)) {
                                retDetail.respCode = "0";
                                retDetail.transState = "PaymentFailed";
                                retDetail.payInfoCode = "";
                                retDetail.respInfo = tmprspmsg;
                                retDetail.reqSeqID = p_req9144.askNumber;
                            } else {
                                retDetail.respCode = "-1";
                                retDetail.respInfo = "银行响应内未找到指定交易，请核对！";
                            }
                        }
                    } else {
                        retDetail.respCode = "-1";
                        if (StringHelper.isNullOrEmpty(tmprspmsg)) {
                            tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                        }
                        retDetail.respInfo = tmprspmsg;
                    }
                } else {
                    retDetail.respCode = "-1";
                    retDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                retDetail.respCode = "-1";
                retDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            retDetail.respCode = "-1";
            retDetail.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        return retDetail;
    }

    //单笔对私实时代扣状态查询
    private RetAtsSglDetail d_9144_b2e0190(ReqQrySingle p_req9144) throws Exception {
        //返回ATS的对象
        RetAtsSglDetail retDetail = new RetAtsSglDetail();
        retDetail.respCode = "";
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0190";
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
            xmlWriter.writeElementClosed("obssid");
            xmlWriter.writeElementString("insid", p_req9144.askNumber);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod1 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg1 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");

                    String tmprspcod2 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg2 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/status/rspmsg");
                    String insid = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/insid");

                    if (StringHelper.hasAnyChar(tmprspcod1) && StringHelper.hasAnyChar(tmprspcod2)) {
                        //retDetail.reqSeqID = tmpBkReader.getFirstText("/bocb2e/trans/trn-"+bankHeader.trncod+"-rs/"+bankHeader.trncod+"-rs/insid");
                        String detailNode = "/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/detail";
                        int tmpCountRow = tmpBkReader.countElement(detailNode);
                        if (tmpCountRow > 0) {
                            retDetail.respCode = "0";
                            if (tmpBkReader.read(detailNode)) {
                                retDetail.transState = tmprspcod2 + "+" + tmpBkReader.readedXElement.getSingleText("trfsta");
                                retDetail.respInfo = tmpBkReader.readedXElement.getSingleText("promsg");
                                retDetail.reqSeqID = insid;
                                retDetail.payInfoCode = retDetail.respInfo;
                            }
                        } else {
                            retDetail.respCode = "0";
                            retDetail.respInfo = tmprspmsg2;
                            retDetail.transState = tmprspcod2;
                            retDetail.reqSeqID = insid;// tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/insid");
                            retDetail.payInfoCode = retDetail.transState;
                        }
                    } else {
                        retDetail.respCode = "-1";
                        retDetail.respInfo = tmprspmsg2;
                        if (StringHelper.isNullOrEmpty(retDetail.respInfo)) {
                            retDetail.respInfo = tmprspmsg1;
                        }
                    }
                } else {
                    retDetail.respCode = "-1";
                    retDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                retDetail.respCode = "-1";
                retDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception e) {
            retDetail.respCode = "-1";
            retDetail.respInfo = e.getMessage();
            e.printStackTrace();
        }
        return retDetail;
    }
}
